package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.ExceptionLog;
import com.blacktry.entity.model.OperationLog;
import com.blacktry.entity.model.request.ExceptionLogRequest;
import com.blacktry.service.ExceptionLogService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2022-01-25
 */
@Api(value = "异常日志模块", tags = "异常日志接口")
@RestController
@RequestMapping("/exception-log")
public class ExceptionLogController {


    @Autowired
    ExceptionLogService exceptionLogService;

    @OperLog(operModul = "异常日志-分页查看异常日志", operType = OprLogConst.SELECT, operDesc = "分页查看异常日志")
    @ApiOperation("分页查看异常日志")
    @PostMapping("/selectExceptionLog/{page}/{size}")
    public ApiResult<Page<ExceptionLog>> selectOperationLog(@RequestBody ExceptionLogRequest exceptionLogRequest, @DefaultValue("1") @PathVariable("page") Integer page, @DefaultValue("6") @PathVariable("size") Integer size) {
        Page<ExceptionLog> logPage = new Page<>(page, size);
        return ApiResultHandler.buildApiResult(200, "请求成功！", exceptionLogService.selectExceptionLog(exceptionLogRequest, logPage));
    }

    @OperLog(operModul = "异常日志-查看详细的异常日志", operType = OprLogConst.SELECT, operDesc = "查看详细的异常日志")
    @ApiOperation("查看详细的异常日志")
    @GetMapping("/selectOneExceptionLog/{id}")
    public ApiResult<OperationLog> selectOneExceptionLog(@PathVariable("id") String id) {
        return ApiResultHandler.buildApiResult(200, "请求成功！", exceptionLogService.getById(id));
    }


}

